# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
import unittest
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from time import sleep
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import HwTestReport
from case.start_appium import get_driver
from HwTestReport import HTMLTestReport
class CaseTest(unittest.TestCase):

    def setUp(self):

        self.imgs = []
        self.driver = get_driver()

    def tearDown(self):
        self.driver.quit()

    def get_screenshot(self):
        self.imgs.append(self.driver.get_screenshot_as_base64())
        return True
    def test_01(self):
        sleep(5)
        el1 = self.driver.find_element_by_xpath(
            "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.Button")
        el1.click()
        self.get_screenshot()
        self.get_screenshot()
    def get_tost_element(self, message):
        tost_element = ("xpath", "//*[contains(@text," + message + ")]")
        return WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(tost_element))


if __name__ == "__main__":
    suite = unittest.TestSuite()
    # 添加要运行的用例
    # suite.addTest(CaseTest("test_02"))
    suite.addTest(CaseTest("test_01",))
    html_file = "../report/Report666.html"
    # 运行容器
    with open(html_file, 'wb') as report:
        runner = HwTestReport.HTMLTestReport(stream=report,
                                             verbosity=2,
                                             title='HwTestReport 测试',
                                             description='带截图，带饼图，带详情',
                                             tester='lee')
        runner.run(suite)